<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.ico">
    <title>Preclinic - Medical & Hospital - Bootstrap 4 Admin Template</title>
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <!--[if lt IE 9]>
		<script src="assets/js/html5shiv.min.js"></script>
		<script src="assets/js/respond.min.js"></script>
	<![endif]-->
</head>

<body>

            <div class="content">
                <div class="row">
                    <div class="col-sm-4 col-3">
                        <h4 class="page-title">医生放号</h4>
                    </div>
                    <div class="col-sm-8 col-9 text-right m-b-20">
                        <a href="javascript:$('#edit').show();" class="btn btn btn-primary btn-rounded float-right"><i class="fa fa-plus"></i> 新增预约</a>
                    </div>
                </div>
				<div class="row">
					<div class="col-md-12">
						<div class="table-responsive">
							<table class="table table-striped custom-table">
								<thead>
									<tr>
										<th>预约编号</th>
										<th>患者名字</th>
										<th>年龄</th>
										<th>医生姓名</th>
										<th>部门</th>
										<th>预约日期</th>
										<th>预约时间</th>
										<th>状态</th>
										<th class="text-right">操作</th>
									</tr>
								</thead>
								<tbody id="doctorAppointment">
								</tbody>
							</table>
						</div>
					</div>
                </div>
            </div>
		<div id="edit" class="col-lg-8 offset-lg-2" style="z-index: 1000; position: absolute; top: 50px; background: #fff; border: solid 1px #ccc; display: none;">
			<form id="summaryForm" enctype="multipart/form-data" method="post" action="/doctor/editDoctor">
				<input type="hidden" id="_id" name="_id"/>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>医生<span class="need_red"> *</span></label>
							<input class="form-control" type="text" id="doctorName" name="doctorName" readonly value="路坎">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>科室<span class="need_red"> *</span></label>
							<input id="doctorSicken" class="form-control" type="text" name="doctorSicken" readonly value="内科">
                        </div>
                    </div>
                </div>
				<div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>日期时间<span class="need_red"> *</span></label>
							<input class="form-control" type="date" id="date" name="date" value="2022-07-25">
                        </div>
                    </div>
					<div class="col-md-3">
                        <div class="form-group">
                            <label>开始时间<span class="need_red"> *</span></label>
							<input class="form-control" type="time" id="timing" name="timing" value="11:15">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>数量<span class="need_red"> *</span></label>
							<input id="num" class="form-control" type="text" name="num" value="5">
                        </div>
                    </div>
                </div>
                <div class="m-t-20 text-center">
					<a href="javascript:submit();" class="btn btn-primary submit-btn"><i class="fa fa-plus"></i><span id="addBtn">添加</span></a>
					<a href="javascript:$('#edit').hide();" class="btn btn-primary submit-btn"><i class="fa fa-plus"></i>取消</a>
                </div>
			</form>
        </div>
    <script src="assets/js/jquery-3.2.1.min.js"></script>
	<script src="assets/js/popper.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>
    <script src="assets/js/select2.min.js"></script>
    <script src="assets/js/app.js"></script>
	 <!--json data-->
	<script type="text/javascript" src="json/appointments.json"></script>
	<script type="text/javascript" src="json/change/add_appointments.json"></script>
	<script type="text/javascript" src="json/doctors.json"></script>
	<script type="text/javascript" src="assets/js/jquerysession.js"></script>
	<script type="text/javascript" src="js/data.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){
		//$("#doctorName").val($.session.get('name'));
		//$("#doctorSicken").val(getSingleData(doctors, 'sicken', 'name=' + $.session.get('name')));
		viewRegistrations(appointments);
	});
	
	function submit(){
		var doctorName = $("#doctorName").val();
		var doctorSicken = $("#doctorSicken").val();
		if(doctorName == null || doctorSicken == ""){
			alert("只有医生才可以增加挂号。");
			return;
		}
		viewRegistrations(this.add_appointments);
		$('#edit').hide();
	}
	
	function del(id){
		update(appointments, 'id=' + id, 'status=作废');
		viewRegistrations(appointments);
	}
	
	function viewRegistrations(appointments){
		var doctorAppointmentStr = "";
		if('administrator' != $.session.get('role')){
			appointments = getData(appointments, 'doctorName=' + $.session.get('name'));
		}
		for(var i = 0; i < appointments.length; i++){
			var appointment = appointments[i];
			doctorAppointmentStr = doctorAppointmentStr + '<tr>';
			doctorAppointmentStr = doctorAppointmentStr + '<td>'+ appointment.num +'</td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td><img width="28" height="28" src="assets/img/user.jpg" class="rounded-circle m-r-5" alt=""> '+ appointment.patientName +'</td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td>'+ appointment.patientAge +'</td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td>'+ appointment.doctorName +'</td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td>'+ appointment.doctorSicken +'</td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td>'+ appointment.date +'</td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td>'+ appointment.timing +'</td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td><span class="custom-badge ';
			if(appointment.status == "完成"){
				doctorAppointmentStr = doctorAppointmentStr + 'status-green';
			}else if(appointment.status == "等候"){
				doctorAppointmentStr = doctorAppointmentStr + 'status-orange';
			}else if(appointment.status == "未使用"){
				doctorAppointmentStr = doctorAppointmentStr + 'status-pink';
			}else if(appointment.status == "诊断中"){
				doctorAppointmentStr = doctorAppointmentStr + 'status-purple';
			}else if(appointment.status == "作废"){
				doctorAppointmentStr = doctorAppointmentStr + 'status-blue';
			}else if(appointment.status == "取消"){
				doctorAppointmentStr = doctorAppointmentStr + 'status-grey';
			}else {
				doctorAppointmentStr = doctorAppointmentStr + 'status-red';
			}
			doctorAppointmentStr = doctorAppointmentStr + '">'+ appointment.status +'</span></td>';
			doctorAppointmentStr = doctorAppointmentStr + '<td class="text-right">';
			doctorAppointmentStr = doctorAppointmentStr + '<div class="dropdown dropdown-action">';
			doctorAppointmentStr = doctorAppointmentStr + '<a href="#" class="action-icon dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-ellipsis-v"></i></a>';
			doctorAppointmentStr = doctorAppointmentStr + '<div class="dropdown-menu dropdown-menu-right">';
			doctorAppointmentStr = doctorAppointmentStr + '<a class="dropdown-item" href="edit-appointment.html"><i class="fa fa-pencil m-r-5"></i> 修改</a>';
			doctorAppointmentStr = doctorAppointmentStr + '<a class="dropdown-item" href="#" onclick="del(\''+appointment.id+'\');"';
			doctorAppointmentStr = doctorAppointmentStr + 'data-toggle="modal" data-target="#delete_appointment"><i class="fa fa-trash-o m-r-5"></i> 删除</a>';
			doctorAppointmentStr = doctorAppointmentStr + '</div>';
			doctorAppointmentStr = doctorAppointmentStr + '</div>';
			doctorAppointmentStr = doctorAppointmentStr + '</td>';
			doctorAppointmentStr = doctorAppointmentStr + '</tr>';
		}
		$("#doctorAppointment").html(doctorAppointmentStr);
	}
	</script>
	<!--json data-->
</body>

</html>